package com.topsail.demo.yyy.facade;

import com.topsail.demo.context.UserContext;
import com.topsail.demo.context.UserContextHolder;
import com.topsail.demo.yyy.api.facade.UserFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;

@Slf4j
@DubboService
public class UserFacadeImpl implements UserFacade {

    @Override
    public String getUserName(Long userId) {
        String crmToken = RpcContext.getServerAttachment().getAttachment("crmToken");
//        UserContext userContext = (UserContext) RpcContext.getServerAttachment().getObjectAttachment("userContext");
//        log.info("crmToken: {}, userContext: {}", crmToken, userContext);

        UserContext userContext = UserContextHolder.getUserContext();
        log.info("crmToken: {}", crmToken);
        log.info("userContext: {}", userContext);
        return RandomStringUtils.randomAlphabetic(8);
    }

}
